from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-19 14:03:57.238947
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 19, Dec, 2021
Time: 14:04:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5496
Nobs: 510.000 HQIC: -48.0039
Log likelihood: 5892.77 FPE: 1.05915e-21
AIC: -48.2969 Det(Omega_mle): 8.89322e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350592 0.078622 4.459 0.000
L1.Burgenland 0.100430 0.043828 2.291 0.022
L1.Kärnten -0.115227 0.022561 -5.107 0.000
L1.Niederösterreich 0.181283 0.090870 1.995 0.046
L1.Oberösterreich 0.126389 0.091847 1.376 0.169
L1.Salzburg 0.283621 0.047132 6.018 0.000
L1.Steiermark 0.022599 0.060857 0.371 0.710
L1.Tirol 0.108053 0.049106 2.200 0.028
L1.Vorarlberg -0.081175 0.043305 -1.875 0.061
L1.Wien 0.029077 0.082706 0.352 0.725
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014317 0.173836 0.082 0.934
L1.Burgenland -0.048560 0.096906 -0.501 0.616
L1.Kärnten 0.035432 0.049883 0.710 0.478
L1.Niederösterreich -0.207464 0.200917 -1.033 0.302
L1.Oberösterreich 0.457540 0.203076 2.253 0.024
L1.Salzburg 0.313669 0.104211 3.010 0.003
L1.Steiermark 0.107272 0.134556 0.797 0.425
L1.Tirol 0.315866 0.108575 2.909 0.004
L1.Vorarlberg 0.011054 0.095748 0.115 0.908
L1.Wien 0.010862 0.182866 0.059 0.953
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222362 0.040062 5.550 0.000
L1.Burgenland 0.092058 0.022333 4.122 0.000
L1.Kärnten -0.005388 0.011496 -0.469 0.639
L1.Niederösterreich 0.225387 0.046303 4.868 0.000
L1.Oberösterreich 0.162368 0.046801 3.469 0.001
L1.Salzburg 0.037489 0.024016 1.561 0.119
L1.Steiermark 0.028744 0.031010 0.927 0.354
L1.Tirol 0.078722 0.025022 3.146 0.002
L1.Vorarlberg 0.055757 0.022066 2.527 0.012
L1.Wien 0.103757 0.042143 2.462 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162748 0.039450 4.125 0.000
L1.Burgenland 0.043462 0.021992 1.976 0.048
L1.Kärnten -0.013383 0.011320 -1.182 0.237
L1.Niederösterreich 0.154532 0.045596 3.389 0.001
L1.Oberösterreich 0.336866 0.046085 7.310 0.000
L1.Salzburg 0.100435 0.023649 4.247 0.000
L1.Steiermark 0.111472 0.030536 3.651 0.000
L1.Tirol 0.090742 0.024640 3.683 0.000
L1.Vorarlberg 0.054566 0.021729 2.511 0.012
L1.Wien -0.042077 0.041499 -1.014 0.311
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146068 0.075050 1.946 0.052
L1.Burgenland -0.036770 0.041837 -0.879 0.379
L1.Kärnten -0.036359 0.021536 -1.688 0.091
L1.Niederösterreich 0.133360 0.086742 1.537 0.124
L1.Oberösterreich 0.183713 0.087674 2.095 0.036
L1.Salzburg 0.256480 0.044991 5.701 0.000
L1.Steiermark 0.078608 0.058092 1.353 0.176
L1.Tirol 0.132531 0.046875 2.827 0.005
L1.Vorarlberg 0.105941 0.041337 2.563 0.010
L1.Wien 0.038943 0.078948 0.493 0.622
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077024 0.059386 1.297 0.195
L1.Burgenland 0.017189 0.033105 0.519 0.604
L1.Kärnten 0.050962 0.017041 2.991 0.003
L1.Niederösterreich 0.182481 0.068637 2.659 0.008
L1.Oberösterreich 0.332995 0.069375 4.800 0.000
L1.Salzburg 0.051464 0.035600 1.446 0.148
L1.Steiermark -0.003737 0.045967 -0.081 0.935
L1.Tirol 0.126057 0.037091 3.399 0.001
L1.Vorarlberg 0.059662 0.032709 1.824 0.068
L1.Wien 0.107212 0.062471 1.716 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170214 0.071961 2.365 0.018
L1.Burgenland 0.011008 0.040115 0.274 0.784
L1.Kärnten -0.060924 0.020650 -2.950 0.003
L1.Niederösterreich -0.111034 0.083172 -1.335 0.182
L1.Oberösterreich 0.233948 0.084066 2.783 0.005
L1.Salzburg 0.039504 0.043139 0.916 0.360
L1.Steiermark 0.262828 0.055701 4.719 0.000
L1.Tirol 0.488886 0.044946 10.877 0.000
L1.Vorarlberg 0.069872 0.039636 1.763 0.078
L1.Wien -0.101434 0.075699 -1.340 0.180
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.144894 0.079683 1.818 0.069
L1.Burgenland -0.012261 0.044420 -0.276 0.783
L1.Kärnten 0.062925 0.022866 2.752 0.006
L1.Niederösterreich 0.175028 0.092097 1.900 0.057
L1.Oberösterreich -0.085547 0.093086 -0.919 0.358
L1.Salzburg 0.224201 0.047768 4.694 0.000
L1.Steiermark 0.136795 0.061678 2.218 0.027
L1.Tirol 0.054902 0.049769 1.103 0.270
L1.Vorarlberg 0.140960 0.043889 3.212 0.001
L1.Wien 0.161810 0.083823 1.930 0.054
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.460231 0.044308 10.387 0.000
L1.Burgenland 0.000103 0.024700 0.004 0.997
L1.Kärnten -0.014378 0.012715 -1.131 0.258
L1.Niederösterreich 0.181507 0.051211 3.544 0.000
L1.Oberösterreich 0.255059 0.051761 4.928 0.000
L1.Salzburg 0.019170 0.026562 0.722 0.470
L1.Steiermark -0.009099 0.034296 -0.265 0.791
L1.Tirol 0.074616 0.027674 2.696 0.007
L1.Vorarlberg 0.056881 0.024405 2.331 0.020
L1.Wien -0.022520 0.046610 -0.483 0.629
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.030003 0.094428 0.157574 0.142430 0.068298 0.080500 0.015441 0.210325
Kärnten 0.030003 1.000000 -0.031823 0.135212 0.051600 0.076064 0.454879 -0.078499 0.101224
Niederösterreich 0.094428 -0.031823 1.000000 0.285849 0.103183 0.256313 0.050267 0.146029 0.253097
Oberösterreich 0.157574 0.135212 0.285849 1.000000 0.199252 0.287404 0.157293 0.129657 0.197092
Salzburg 0.142430 0.051600 0.103183 0.199252 1.000000 0.122717 0.060025 0.110924 0.071069
Steiermark 0.068298 0.076064 0.256313 0.287404 0.122717 1.000000 0.132229 0.090834 0.012302
Tirol 0.080500 0.454879 0.050267 0.157293 0.060025 0.132229 1.000000 0.064028 0.126092
Vorarlberg 0.015441 -0.078499 0.146029 0.129657 0.110924 0.090834 0.064028 1.000000 -0.005430
Wien 0.210325 0.101224 0.253097 0.197092 0.071069 0.012302 0.126092 -0.005430 1.000000